//201902104030_何琛选
package test;

import cn.edu.sdjzu.xg.bysj.domain.Teacher;
import cn.edu.sdjzu.xg.bysj.service.TeacherService;
import util.bysjException;

import java.io.*;
import java.sql.SQLException;

public class Add_Teacher_test {
    public static void main(String[] args) {
        try {

            System.out.println(TeacherService.getInstance().find(8));
            Teacher teacher1 = new Teacher("教师9","09");
            TeacherService.getInstance().add(teacher1);

            //以文件输出流为参数创建对象输出流（覆盖写入模式）
            ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("teacher.dat"));
            //将对象写入输出流
            oos.writeObject(teacher1);
            oos.close();

//            //读取
//            ObjectInputStream ois = new ObjectInputStream(new FileInputStream("teacher.dat"));
//            Object object = ois.readObject();
//            //将Object对象转换为Teacher类型
//            Teacher teacherOis= (Teacher) object;
//            ois.close();
//            System.out.println(teacherOis);

        }catch (SQLException e){
            System.out.println("数据库操作异常");
        } catch (bysjException message){
            System.out.println(message);
        }catch (IOException e){
            System.out.println(e);
        } catch (Exception e){
            System.out.println(e);
        }
    }
}
